home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / c-runtime / tests / test.m < prev   
Encoding:
Text File  |  1992-08-18  |  18.5 KB  |  538 lines

  1. /* -*-objc-*- */
  2.  
  3. /* 
  4.   $Header$
  5.   $Author: dglattin $
  6.   $Date$
  7.   $Log$
  8.  */
  9.  
  10. #include  <objc.h>
  11. #include  <objc-proto.h>
  12.  
  13. #include  <Object.h>
  14. #include  <SubClass1.h>
  15. #include  <SubClass2.h>
  16. #include  <SubClass3.h>
  17. #include  <SubClass4.h>
  18. #include  <SubClass5.h>
  19. #include  <Confuse.h>
  20. #include  <ConfuseMore.h>
  21.  
  22. #include  <assert.h>
  23. #include  <fcntl.h>
  24. #include  <limits.h>
  25. #include  <stdlib.h>
  26. #include  <stdio.h>
  27. #include  <sys/file.h>
  28. #include  <time.h>
  29.  
  30.  
  31. void  func (void) {
  32.  
  33. }
  34.  
  35.  
  36. /*
  37.  * These tests should be self explanatory but I'll
  38.  *  narrate anyway.
  39.  */
  40. int main (int argc, char* argv[]) {
  41.  
  42.   Object      *myObject = NULL,
  43.               *aCopy = NULL;
  44.   SubClass1*  sc1;
  45.   SubClass2*  sc2;
  46.   SubClass3*  sc3;
  47.   SubClass4*  sc4;
  48.   SubClass5*  sc5;
  49.   Ivar_t      aIvar;
  50.   SEL         aSel;// = @selector (newOther);
  51.   int         fd;
  52.  
  53.  
  54. objcInitCleanup();
  55.   aSel = @selector (newOther);
  56.  
  57.   printf( "Start of tests.  If you get here you're doing well.\n");
  58.  
  59.   /* Preposing tests. */
  60.   assert([ SubClass2 superClass ] == [ SubClass1 superClass ]);
  61.  
  62.   /* Should be interesting. */
  63.   [ SubClass4 poseAs:[ SubClass1 class ]];
  64.  
  65.  
  66.   /* Make a object then copy it.
  67.     They should be different. */
  68.   myObject = [ Object new ];
  69.   aCopy = [ myObject copy ];
  70.   assert(myObject != aCopy);
  71.   
  72.   /* I hope nobody returned NULL. */
  73.   assert(myObject);
  74.   assert(aCopy);
  75.  
  76.   /* Get Object's class struct. */
  77.   assert([ Object class ]); 
  78.   
  79.   /* Object's class name should be "Object". */ 
  80.   assert(!strcmp (class_getClassName ([ Object class ]), "Object"));
  81.   
  82.   /* Object's super class is NULL  (no super class). */
  83.   assert(![ Object superClass ]);
  84.  
  85.   /* Send more factory methods to Object.
  86.     See if they respond  (or don't respond) to some methods. 
  87.     Instances don't respond to factory methods.
  88.     They respond to instance methods.
  89.     They should not respond to methods not in their specification. */
  90.   assert(![ Object instancesRespondTo:@selector (new)]);
  91.   assert([ Object instancesRespondTo:@selector (name)]);
  92.   assert(![Object instancesRespondTo:@selector (__not_probable_method__)]);
  93.  
  94.   /* See if we can set and interrogate a class's
  95.     version. */
  96.   [ Object setVersion:217 ];
  97.   assert(217 == [ Object version ]);
  98.   
  99.   /* self should work. */
  100.   assert(myObject == [ myObject self ]);
  101.  
  102.   /* Test a couple of paths to Object's class name. */
  103.   assert(!strcmp ([ myObject name ], "Object"));
  104.   assert(!strcmp ([ myObject name ], object_getClassName (myObject)));
  105.   assert(!strcmp ((char*)[ myObject perform:@selector (name)], [ myObject name ]));
  106.  
  107.   /* Class of factory object and its instance should be
  108.     the same. */
  109.   assert([ Object class ] == [ myObject class]);
  110.  
  111.   /* Super class of Object is NULL. */
  112.   assert([ Object superClass ] == [ myObject superClass ]);
  113.   assert(![myObject superClass ]);
  114.   assert(![ Object superClass ]);
  115.  
  116.   /* A instance of Object is a kindOf Object and
  117.     a member of its hierarchy. */
  118.   assert([ myObject isKindOf:[ Object class ]]);
  119.   assert([ myObject isKindOfGivenName:"Object" ]);
  120.   assert([ myObject isMemberOf:[ Object class ]]);
  121.   assert([ myObject isMemberOfGivenName:"Object" ]);
  122.  
  123.   /* Like the factory object, instances can
  124.     be tested for responding to selecotrs too. */
  125.   assert(![ myObject respondsTo:@selector (new)]);
  126.   assert([ myObject respondsTo:@selector (hash)]);
  127.   assert(![ myObject respondsTo:@selector (__not_probable_method__)]);
  128.  
  129.   /* Test common features between a object and its copy. */
  130.   assert([ aCopy class ] == [ myObject class ]);
  131.   assert([ aCopy superClass ] == [ myObject superClass ]);
  132.  
  133.   /* -free methods are suppose to return nil. */
  134.   assert(![ aCopy free ]);
  135.   
  136.   /* Check some differences between Object factory
  137.     and a subclass's factory. */
  138.   assert([ SubClass1 version ] != [ Object version ]);
  139.   assert([ SubClass1 class ] != [ Object class ]);
  140.   assert([ SubClass1 superClass ] != [ Object superClass ]);
  141.   assert(![ Object instancesRespondTo:@selector (hokeyMethod)]);
  142.   assert([ SubClass1 instancesRespondTo:@selector (hokeyMethod)]);
  143.  
  144.   /* Create a subclass instances and free it. */
  145.   sc1 = [ SubClass1 new ];
  146.   assert(sc1);
  147.   assert(![ sc1 free ]);
  148.   
  149.   /* uh, make another. */
  150.   sc1 = [ SubClass1 newOther ];
  151.   assert(sc1);
  152.   
  153.   /* hokey returns self.  Is it the same as self? */
  154.   assert([ sc1 self ] == [ sc1 hokeyMethod ]);
  155.   
  156.   /* Indirectly tell the subclass to do something. */
  157.   [ sc1 perform:@selector (print) ];
  158.   [ sc1 perform:@selector (print:) with: (id)"this is a message sent to " 
  159.     "a instance of SubClass1 in a weird way" ];
  160.  
  161.   /* Get the address of some of instance variables of
  162.     the subclass.  Some of the variables we're looking for
  163.     aren't defined in the class.  test that too. */
  164.   aIvar = object_getIvarAddress (sc1, "isa");
  165.   assert(aIvar);
  166.   aIvar = object_getIvarAddress (sc1, "shit");
  167.   assert(!aIvar);
  168.   aIvar = object_getIvarAddress (sc1, "dumb");
  169.   assert(aIvar);
  170.  
  171.   /* More name checking */
  172.   assert(!strcmp ([ sc1 name ], "SubClass1"));
  173.   assert(!strcmp ([ sc1 name ], object_getClassName (sc1)));
  174.   assert(!strcmp ((char*)[ sc1 perform:@selector (name)], [ sc1 name ]));
  175.  
  176.   /* Have the tester check this info. S/he isn't doing anything. */
  177.   printf ("obj=%s, ivar=%s, offset=%d, obj size=%d\n", 
  178.     [ sc1 name ], aIvar->ivar_name, 
  179.     aIvar->ivar_offset, [ sc1 class ]->instance_size );
  180.  
  181.  
  182.   /* Different subclass of Object. */
  183.   
  184.   /* Check some factory differences between Subclass2,
  185.     Subclass1 and Object. */
  186.   assert([ SubClass2 version ] != [ Object version ]);
  187.   assert([ SubClass1 version ] == [ SubClass2 version ]);
  188.   assert([ SubClass2 class ] != [ Object class ]);
  189.   assert([ SubClass2 class ] != [ SubClass1 class ]);
  190.   assert([ SubClass2 superClass ] != [ Object superClass ]);
  191.   assert([ SubClass2 superClass ] != [ SubClass1 superClass ]);
  192.   assert([ SubClass2 instancesRespondTo:@selector (print:with:)]);
  193.   assert(![ SubClass1 instancesRespondTo:@selector (print::)]);
  194.  
  195.   /* Create a instance.  SubClass2 doesn't define +new
  196.     but it should be found in a super class. */
  197.   sc2 = [ SubClass2 new ];
  198.   assert(sc2);
  199.   
  200.   /* More name checking */
  201.   assert(!strcmp ([ sc2 name ], "SubClass2"));
  202.   assert(!strcmp ([ sc2 name ], object_getClassName (sc2)));
  203.   assert(!strcmp ((char*)[ sc2 perform:@selector (name)], [ sc2 name ]));
  204.   
  205.   /* Free the instance and makke sure its gone.
  206.     Subclass2 doesn't define -free so its super class
  207.     handles this one too. */
  208.   assert(![ sc2 free ]);
  209.   
  210.   /* Subclass2 defines this factory method to create instances. */
  211.   sc2 = [ SubClass2 newOther ];
  212.   assert(sc2);
  213.  
  214.   /* More name checking */
  215.   assert(!strcmp ([ sc2 name ], "SubClass2"));
  216.   assert(!strcmp ([ sc2 name ], object_getClassName (sc2)));
  217.   assert(!strcmp ((char*)[ sc2 perform:@selector (name)], [ sc2 name ]));
  218.  
  219.   /* Super class call to self should return the same
  220.     value as hokey. */
  221.   assert([ sc2 self ] == [ sc2 hokeyMethod ]);
  222.   
  223.   /* These should be different. */
  224.   assert([ sc2 self ] != [ sc1 self ]);
  225.   
  226.   /* More name checking */
  227.   assert(!strcmp ([ sc2 name ], "SubClass2"));
  228.   assert(!strcmp ([ sc2 name ], object_getClassName (sc2)));
  229.   assert(!strcmp ((void*)[ sc2 perform:@selector (name)], [ sc2 name ]));
  230.  
  231.   /* Indirectly tell SubClass2 to do something. */
  232.   [ sc2 perform:@selector (print) ];
  233.   [ sc2 perform:@selector (print:) with: (id)"a message" ];
  234.   [ sc2 perform:@selector (print:) with: (id)"this is a message sent to " 
  235.     "a instance of SubClass2 in a weird way" ];
  236.  
  237.   /* Get the address of some of instance variables of
  238.     the subclass.  Some of the variables we're looking for
  239.     aren't defined in the class.  test that too. */
  240.   aIvar = object_getIvarAddress (sc2, "isa");
  241.   assert(aIvar);
  242.   aIvar = object_getIvarAddress (sc2, "dumb");
  243.   assert(aIvar);
  244.   
  245.   /* Isn't the tester person doing anything yet? */
  246.   printf ("obj=%s, ivar=%s, offset=%d, obj size=%d\n", 
  247.     [ sc2 name ], aIvar->ivar_name, 
  248.     aIvar->ivar_offset, [ sc2 class ]->instance_size );
  249.  
  250.  
  251.   /* Test a subclass of a subclass. */
  252.  
  253.   /* Factory method difference tests. */
  254.   assert([ SubClass3 version ] != [ Object version ]);
  255.   assert([ SubClass3 version ] == [ SubClass2 version ]);
  256.   assert([ SubClass3 class ] != [ SubClass2 class ]);
  257.   assert([ SubClass3 class ] != [ SubClass1 class ]);
  258.   assert([ SubClass3 class ] != [ Object class ]);
  259.   assert([ SubClass2 superClass ] != [ Object superClass ]);
  260.   assert([ SubClass3 superClass ] != [ SubClass2 superClass ]);
  261.   assert([ SubClass3 superClass ] != [ SubClass1 superClass ]);
  262.   assert([ SubClass3 instancesRespondTo:@selector (print:with:)]);
  263.   assert([ SubClass3 instancesRespondTo:@selector (print:)]);
  264.   
  265.   /* SubClass defines +new but its super class doesn't. */
  266.   sc3 = [ SubClass3 new ];
  267.   assert(sc3);
  268.   
  269.   /* More name checking */
  270.   assert(!strcmp ([ sc3 name ], "SubClass3"));
  271.   assert(!strcmp ([ sc3 name ], object_getClassName (sc3)));
  272.   assert(!strcmp ((char*)[ sc3 perform:@selector (name)], [ sc3 name ]));
  273.  
  274.   /* GO AWAY! */
  275.   assert(![ sc3 free ]);
  276.   
  277.   /* WAIT!  COME BACK! */
  278.   sc3 = [ SubClass3 new ];
  279.   assert(sc3);
  280.  
  281.   /* Check self. */
  282.   assert([ sc3 self ] == [ sc3 hokeyMethod ]);
  283.   assert([ sc3 self ] != [ sc1 self ]);
  284.   assert([ sc3 self ] != [ sc2 self ]);
  285.   
  286.   /* Indirectly tell SubClass3 to do something. */
  287.   [ sc3 perform:@selector (print) ];
  288.   [ sc3 perform:@selector (print:) with: (id)"a message" ];
  289.   [ sc3 perform:@selector (print:) with: (id)"this is a message sent to " 
  290.     "a instance of SubClass2 in a weird way" ];
  291.  
  292.   /* Check to see if some instance variables exist. */
  293.   aIvar = object_getIvarAddress (sc3, "isa");
  294.   assert(aIvar);
  295.   aIvar = object_getIvarAddress (sc3, "dumb");
  296.   assert(aIvar);
  297.   aIvar = object_getIvarAddress (sc3, "smart");
  298.   assert(aIvar);
  299.   
  300.   /* Asleep yet? */
  301.   printf ("obj=%s, ivar=%s, offset=%d, obj size=%d\n", 
  302.     [ sc3 name ], aIvar->ivar_name, 
  303.     aIvar->ivar_offset, [ sc3 class ]->instance_size );
  304.  
  305.  
  306.   /* Category testing. */
  307.   assert([ SubClass1 instancesRespondTo:@selector (additionalMethod1)]);
  308.   assert([ SubClass1 instancesRespondTo:@selector (additionalMethod2)]);
  309.   assert([ SubClass1 instancesRespondTo:@selector (additionalMethod3)]);
  310.   assert([ SubClass1 instancesRespondTo:@selector (additionalMethod4)]);
  311.   assert([ SubClass1 instancesRespondTo:@selector (additionalMethod5)]);
  312.   assert([ SubClass1 instancesRespondTo:@selector (additionalMethod_2)]);
  313.   assert([ SubClass1 instancesRespondTo:@selector (additionalMethod_3)]);
  314.   assert([ sc1 respondsTo:@selector (additionalMethod1)]);
  315.   assert([ sc1 respondsTo:@selector (additionalMethod2)]);
  316.   assert([ sc1 respondsTo:@selector (additionalMethod3)]);
  317.   assert([ sc1 respondsTo:@selector (additionalMethod4)]);
  318.   assert([ sc1 respondsTo:@selector (additionalMethod5)]);
  319.   assert([ sc1 respondsTo:@selector (additionalMethod_2)]);
  320.   assert([ sc1 respondsTo:@selector (additionalMethod_3)]);
  321.   
  322.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod1)]);
  323.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod2)]);
  324.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod3)]);
  325.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod4a)]);
  326.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod5a)]);
  327.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod6a)]);
  328.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod7a)]);
  329.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod8a)]);
  330.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod_1)]);
  331.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod_2)]);
  332.   assert([ SubClass2 instancesRespondTo:@selector (additionalMethod_3)]);
  333.   assert([ sc2 respondsTo:@selector (additionalMethod1)]);
  334.   assert([ sc2 respondsTo:@selector (additionalMethod2)]);
  335.   assert([ sc2 respondsTo:@selector (additionalMethod3)]);
  336.   assert([ sc2 respondsTo:@selector (additionalMethod4a)]);
  337.   assert([ sc2 respondsTo:@selector (additionalMethod5a)]);
  338.   assert([ sc2 respondsTo:@selector (additionalMethod6a)]);
  339.   assert([ sc2 respondsTo:@selector (additionalMethod7a)]);
  340.   assert([ sc2 respondsTo:@selector (additionalMethod8a)]);
  341.   assert([ sc2 respondsTo:@selector (additionalMethod_1)]);
  342.   assert([ sc2 respondsTo:@selector (additionalMethod_2)]);
  343.   assert([ sc2 respondsTo:@selector (additionalMethod_3)]);
  344.  
  345.   assert([ SubClass3 instancesRespondTo:@selector (additionalMethod1a)]);
  346.   assert([ SubClass3 instancesRespondTo:@selector (additionalMethod2a)]);
  347.   assert([ SubClass3 instancesRespondTo:@selector (additionalMethod_1a)]);
  348.   assert([ SubClass3 instancesRespondTo:@selector (additionalMethod_2a)]);
  349.  
  350.   assert([ sc3 respondsTo:@selector (additionalMethod1a)]);
  351.   assert([ sc3 respondsTo:@selector (additionalMethod2a)]);
  352.   assert([ sc3 respondsTo:@selector (additionalMethod_1a)]);
  353.   assert([ sc3 respondsTo:@selector (additionalMethod_2a)]);
  354.  
  355.   /* YEA YOU!  Wake up! */
  356.   [ SubClass3 additionalClassMethod ];
  357.   [ SubClass3 additionalClassMethodTwo ];
  358.  
  359.  
  360.   /* Relationship tests. 
  361.     This sequence tests isKindOfGivenName: too. */
  362.   assert([ myObject isKindOf:[ Object class ]]);
  363.   assert([ sc1 isKindOf:[ Object class ]]);
  364.   assert([ sc2 isKindOf:[ Object class ]]);
  365.   assert([ sc3 isKindOf:[ Object class ]]);
  366.   assert([ sc1 isKindOf:[ SubClass1 class ]]);
  367.   assert([ sc2 isKindOf:[ SubClass2 class ]]);
  368.   assert([ sc3 isKindOf:[ SubClass3 class ]]);
  369.   assert([ sc3 isKindOf:[ SubClass2 class ]]);
  370.   assert(![ sc2 isKindOf:[ SubClass1 class ]]);
  371.  
  372.   /* More relationship tests.
  373.     This sequence tests isMemberOfGivenName: too. */
  374.   assert([ myObject isMemberOf:[ Object class ]]);
  375.   assert([ sc1 isMemberOf:[ SubClass1 class ]]);
  376.   assert([ sc2 isMemberOf:[ SubClass2 class ]]);
  377.   assert([ sc3 isMemberOf:[ SubClass3 class ]]);
  378.  
  379.   /* More relationship tests. */
  380.   assert(![ myObject isMemberOf:[ SubClass1 class ]]);
  381.   assert(![ myObject isMemberOf:[ SubClass2 class ]]);
  382.   assert(![ myObject isMemberOf:[ SubClass3 class ]]);
  383.   assert(![ sc1 isMemberOf:[ Object class ]]);
  384.   assert(![ sc1 isMemberOf:[ SubClass2 class ]]);
  385.   assert(![ sc1 isMemberOf:[ SubClass3 class ]]);
  386.   assert(![ sc2 isMemberOf:[ Object class ]]);
  387.   assert(![ sc2 isMemberOf:[ SubClass1 class ]]);
  388.   assert(![ sc2 isMemberOf:[ SubClass3 class ]]);
  389.   assert(![ sc3 isMemberOf:[ Object class ]]);
  390.   assert(![ sc3 isMemberOf:[ SubClass1 class ]]);
  391.   assert(![ sc3 isMemberOf:[ SubClass2 class ]]);
  392.  
  393.  
  394.   /* Archiving */
  395.   fd = open  ("/tmp/shit.arcv", O_CREAT | O_TRUNC | O_RDWR, 0666);
  396.   assert  (fd >= 0);
  397.   sc1 = [ SubClass1 new ];
  398.   sc2 = [ SubClass2 new ];
  399.   sc3 = [ SubClass3 new ];
  400.   sc4 = [ SubClass4 new ];
  401.   sc5 = [ SubClass5 new ];
  402.   
  403.   [ sc5 storeOn:fd ];
  404.   [ sc3 storeOn:fd ];
  405.   [ sc1 storeOn:fd ];
  406.   [ sc4 storeOn:fd ];
  407.   [ sc2 storeOn:fd ];
  408.   
  409.   lseek  (fd, 0, L_SET);
  410.   assert  (fd >= 0);
  411.   
  412.   sc5 = [ SubClass5 readFrom:fd ];
  413.   sc3 = [ SubClass3 readFrom:fd ];
  414.   sc1 = [ SubClass1 readFrom:fd ];
  415.   sc4 = [ SubClass4 readFrom:fd ];
  416.   sc2 = [ SubClass2 readFrom:fd ];
  417.  
  418.   assert  (!strcmp ([ sc1 name ], "SubClass1"));
  419.   assert  (!strcmp ([ sc2 name ], "SubClass2"));
  420.   assert  (!strcmp ([ sc3 name ], "SubClass3"));
  421.   assert  (!strcmp ([ sc4 name ], "SubClass4"));
  422.   assert  (!strcmp ([ sc5 name ], "SubClass5"));
  423.  
  424.   close  (fd);
  425.  
  426.  
  427.   /* Posing tests */
  428.   assert([ SubClass1 return12 ] == 13);
  429.   assert([ SubClass4 return12 ] == 13);
  430.   sc1 = [ SubClass1 new ];
  431.   assert([ sc1 return15 ] == 15);
  432.   assert([ sc1 return24 ] == 24);
  433.   assert([ SubClass5 return12 ] == 12);
  434.   sc5 = [ SubClass5 new ];
  435.   assert([ sc5 return15 ] == 15);
  436.   assert([ sc5 return24 ] == 24);
  437.   assert([ sc5 return33 ] == 34);
  438.   assert([ sc5 return45 ] == 45); /* this will work but is an
  439.                                       error.  */
  440.  
  441.  
  442.   printf ("Exit, the tests worked! "
  443.     " (you did compile with -DDEBUG -UNDEBUG didn't you?)\n");
  444.  
  445.  
  446.   /* Performance measurement stuff. */
  447.   printf ("\n\nSome performance data:\n\n");
  448.   
  449.   { /* Coloring alogorithm of the compiler should make
  450.       this fast. */
  451. #define ITERATIONS  1000000
  452.  
  453.     int         i;
  454.     time_t      startTime, diffTime;
  455.     id          aObj;
  456.  
  457.     startTime = time (NULL);
  458.     for (i = 0; i < ITERATIONS; ++i)
  459.       func ();
  460.     diffTime = time (NULL) - startTime ;
  461.     printf ("for (i = 0; i < ITERATIONS; ++i)\n");
  462.     printf ("  func ();\n");
  463.     printf ("%d iterations, %d sec  (%g/sec)\n\n",
  464.       ITERATIONS, diffTime, (double)ITERATIONS/diffTime);
  465.  
  466. #if 0
  467.     startTime = time (NULL);
  468.     for (i = 0; i < ITERATIONS; ++i)
  469.       [[ Object new ] free ];
  470.     diffTime = time (NULL) - startTime ;
  471.     printf ("for (i = 0; i < ITERATIONS; ++i)\n");
  472.     printf ("  [[ Object new ] free ];\n");
  473.     printf ("%d iterations, %d sec  (%g/sec)\n\n",
  474.       ITERATIONS, diffTime, (double)ITERATIONS/diffTime);
  475.  
  476.     startTime = time (NULL);
  477.     for (i = 0; i < ITERATIONS; ++i)
  478.       [[ SubClass2 new ] free ];
  479.     diffTime = time (NULL) - startTime ;
  480.     printf ("for (i = 0; i < ITERATIONS; ++i)\n");
  481.     printf ("  [[ SubClass2 new ] free ];\n");
  482.     printf (" (super class must be searched for +new)\n");
  483.     printf ("%d iterations, %d sec  (%g/sec)\n\n",
  484.       ITERATIONS, diffTime, (double)ITERATIONS/diffTime);
  485.   
  486.     startTime = time (NULL);
  487.     for (i = 0; i < ITERATIONS; ++i)
  488.       [[ SubClass2 newOther ] free ];
  489.     diffTime = time (NULL) - startTime ;
  490.     printf ("for (i = 0; i < ITERATIONS; ++i)\n");
  491.     printf ("  [[ SubClass2 newOther ] free ];\n");
  492.     printf (" (+newOther calls +new in its super class)\n");
  493.     printf ("%d iterations, %d sec  (%g/sec)\n\n",
  494.       ITERATIONS, diffTime, (double)ITERATIONS/diffTime);
  495. #endif
  496.  
  497.     aObj = [ Object new ];
  498.     startTime = time (NULL);
  499.     for (i = 0; i < ITERATIONS; ++i)
  500.       [ aObj self ];
  501.     diffTime = time (NULL) - startTime ;
  502.     printf ("aObj = [ Object new ];\n");
  503.     printf ("for (i = 0; i < ITERATIONS; ++i)\n");
  504.     printf ("  [ aObj self ];\n");
  505.     printf ("%d iterations, %d sec  (%g/sec)\n\n",
  506.       ITERATIONS, diffTime, (double)ITERATIONS/diffTime);
  507.     [ aObj free ];
  508.  
  509.     aObj = [ SubClass3 new ];
  510.     startTime = time (NULL);
  511.     for (i = 0; i < ITERATIONS; ++i)
  512.       [ aObj self ];
  513.     diffTime = time (NULL) - startTime ;
  514.     printf ("aObj = [ SubClass3 new ];\n");
  515.     printf ("for (i = 0; i < ITERATIONS; ++i)\n");
  516.     printf ("  [ aObj self ];\n");
  517.     printf (" (-self is implemented two classes up)\n");
  518.     printf ("%d iterations, %d sec  (%g/sec)\n\n",
  519.       ITERATIONS, diffTime, (double)ITERATIONS/diffTime);
  520.     [ aObj free ];
  521.  
  522.     aObj = [ SubClass3 new ];
  523.     startTime = time (NULL);
  524.     for (i = 0; i < ITERATIONS; ++i)
  525.       [[ aObj self ] self ];
  526.     diffTime = time (NULL) - startTime ;
  527.     printf ("aObj = [ SubClass3 new ];\n");
  528.     printf ("for (i = 0; i < ITERATIONS; ++i)\n");
  529.     printf ("  [[ aObj self ] self ];\n");
  530.     printf ("%d iterations, %d sec  (%g/sec)\n\n",
  531.       ITERATIONS, diffTime, (double)ITERATIONS/diffTime);
  532.     [ aObj free ];
  533.   }
  534.   
  535.   
  536.   return 0;
  537. }
  538.